added SSCLI 1.0
[windows-sources.git] / shared source / sscli20 / tools / nmake / macro.cpp
blobb6812a3d50b72b61c6d3e78e871a65e9ccb3b400
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
14 // ==--==
15 // Macro.C - contains routines that have to do with macros
17 // Purpose:
18 // Contains routines that have to do with macros
20 #include "precomp.h"
21 #ifdef _MSC_VER
22 #pragma hdrstop
23 #endif
25 static STRINGLIST **lastMacroChain = NULL;
27 // findMacro - look up a string in a hash table
29 // Look up a macro name in a hash table and return the entry
30 // or NULL.
31 // If a macro and undefined, return NULL.
33 MACRODEF * findMacro(char *str)
35 unsigned n;
36 char *string = str;
37 STRINGLIST *found;
39 if (*string) {
40 for (n = 0; *string; n += *string++); //Hash
41 n %= MAXMACRO;
42 #if defined(STATISTICS)
43 CntfindMacro++;
44 #endif
45 lastMacroChain = (STRINGLIST **)&macroTable[n];
46 for (found = *lastMacroChain; found; found = found->next) {
47 #if defined(STATISTICS)
48 CntmacroChains++;
49 #endif
50 if (!_tcscmp(found->text, str)) {
51 return((((MACRODEF *)found)->flags & M_UNDEFINED) ? NULL : (MACRODEF *)found);
54 } else {
55 // set lastMacroChain, even for an empty name
56 lastMacroChain = (STRINGLIST **)&macroTable[0];
58 return(NULL);
61 // insertMacro
63 // Macro insertion requires that we JUST did a findMacro, which action set lastMacroChain.
65 void insertMacro(STRINGLIST * p)
67 #ifdef STATISTICS
68 CntinsertMacro++;
69 #endif
70 assert(lastMacroChain != NULL);
71 prependItem(lastMacroChain, p);
72 lastMacroChain = NULL;
75 // Init the macro table to a known state before continuing.
77 void initMacroTable(MACRODEF *table[])
79 unsigned num;
80 for (num = 0; num < MAXMACRO; num++) {
81 table[num] = NULL;